package android.slc.box.core.widget.toggle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;

/**
 * @author slc
 * @date 2023/10/8
 **/
public class ToggleGroupCompat {
    private final ToggleGroup toggleGroup;

    public ToggleGroupCompat(ToggleGroup toggleGroup) {
        this.toggleGroup = toggleGroup;
    }

    public void applyOnly() {
        toggleGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
            @Override
            public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
                if (newValue == null && oldValue != null) {
                    oldValue.setSelected(true);
                }
            }
        });
    }
}
